/**
 * MemberProfileController.java
 * 
 * Copyright@2015 OVT Inc. All rights reserved. 
 * 
 * Dec 30, 2015
 */
package com.ovt.doorbell.payment.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ovt.doorbell.payment.api.response.DoorbellPaymentAPIResult;
import com.ovt.doorbell.payment.common.model.JsonDocument;
import com.ovt.doorbell.payment.common.utils.StringUtils;
import com.ovt.doorbell.payment.dao.vo.FullMemberProfile;
import com.ovt.doorbell.payment.service.MemberProfileService;
import com.ovt.doorbell.payment.service.context.SessionContext;
import com.ovt.doorbell.payment.service.exception.ServiceException;

/**
 * MemberProfileController
 * 
 * @Author zhi.liu
 * @Version 1.0
 * @See 
 * @Since [OVT Cloud Platform]/[API] 1.0
 */
@Controller
@RequestMapping("/profile")
public class MemberProfileController
{
    @Autowired
    private MemberProfileService memberProfileService;

    @RequestMapping("/current")
    public JsonDocument getCurrentProfile(@RequestParam String deviceId) throws ServiceException
    {
        String userId = SessionContext.getCurrentUser().getId() + StringUtils.UNDER_LINE + deviceId;
        
        FullMemberProfile memberProfile = memberProfileService.getFullMemberProfile(userId);
        
        return new DoorbellPaymentAPIResult(memberProfile);
    }
    
    @RequestMapping("/getCancelInfo")
    public JsonDocument getCancelProfile(@RequestParam String deviceId) throws ServiceException
    {
        String userId = SessionContext.getCurrentUser().getId() + StringUtils.UNDER_LINE + deviceId;
        
        memberProfileService.preCancelProfile(userId);
        
        return new DoorbellPaymentAPIResult();
    }
    
    @RequestMapping("/cancel")
    public JsonDocument cancelProfile(@RequestParam String deviceId) throws ServiceException
    {
        String userId = SessionContext.getCurrentUser().getId() + StringUtils.UNDER_LINE + deviceId;
        
        FullMemberProfile memberProfile = memberProfileService.getFullMemberProfile(userId);
        
        return new DoorbellPaymentAPIResult(memberProfile);
    }
}
